package com.lanou.mynews.main;



import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;

import com.lanou.mynews.R;
import com.lanou.mynews.dao.DaoMaster;
import com.lanou.mynews.dao.DaoSession;
import com.lanou.mynews.issue.IssueFragment;
import com.lanou.mynews.movie.MovieFragment;
import com.lanou.mynews.news.NewsFragment;
import com.lanou.mynews.video.MyVideoFragment;

import java.util.ArrayList;



public class MainActivity extends AppCompatActivity {
    private android.support.v7.widget.Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;

    //抽屉
    private DrawerLayout mDrawerLayout;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.tb);
//        toolbar.setTitle("资讯独占");
        init();
    }

    private void init() {
        tabLayout = (TabLayout) findViewById(R.id.tablayout);
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        FragementAdapter adapter = new FragementAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        tabLayout.setTabTextColors(getResources().getColor(R.color.tabBarColor), getResources().getColor(R.color.tabBarColor));
        tabLayout.setBackgroundColor(getResources().getColor(R.color.juhuang3));

        //  tabLayout.setTabsFromPagerAdapter(com.lanou.mynews.adapter);

        //抽屉-----------------------
        mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawerlayout2);
        mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {


            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {

            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });




        mDrawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }
        });









    }

    /** 能不能别随手起名字 */
    private class FragementAdapter extends FragmentPagerAdapter {
        private ArrayList<Fragment> datas;
        private String[] titles = {"头条", "视听", "影讯", "话题"};

        public FragementAdapter(FragmentManager fm) {
            super(fm);
            initData();
        }

        private void initData() {
            datas = new ArrayList<>();
            datas.add(new NewsFragment());
            datas.add(new MyVideoFragment());
            datas.add(new MovieFragment());
            datas.add(new IssueFragment());

        }

        @Override
        public Fragment getItem(int position) {
            return datas.get(position);
        }

        @Override
        public int getCount() {
            return datas.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            //super.destroyItem(container, position, object);
        }
    }

}
